package com.anjian.bamin.anjiandianzimap.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aiton.administrator.shane_library.shane.ZjbBaseActivity;
import com.amap.api.navi.model.NaviLatLng;
import com.anjian.bamin.anjiandianzimap.R;
import com.anjian.bamin.anjiandianzimap.contant.Constant;
import com.anjian.bamin.anjiandianzimap.model.CompanyInfo;
import com.blankj.utilcode.utils.ToastUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CompanyDetialActivity extends ZjbBaseActivity implements View.OnClickListener {

    @Bind(R.id.textView_company)
    TextView mTextViewCompany;
    @Bind(R.id.textViewCompanyName)
    TextView mTextViewCompanyName;
    @Bind(R.id.textViewAddress)
    TextView mTextViewAddress;
    @Bind(R.id.textViewPhone)
    TextView mTextViewPhone;
    @Bind(R.id.image_menu)
    ImageView mImageMenu;
    @Bind(R.id.textViewCorporate)
    TextView mTextViewCorporate;
    @Bind(R.id.textViewType)
    TextView mTextViewType;
    @Bind(R.id.textView_Administrator)
    TextView mTextViewAdministrator;
    @Bind(R.id.textView_Administrator_phone)
    TextView mTextViewAdministratorPhone;
    @Bind(R.id.rela_company_GPS)
    RelativeLayout mRelaCompanyGPS;
    @Bind(R.id.rela_company_inspection_record)
    RelativeLayout mRelaCompanyInspectionRecord;
    @Bind(R.id.rela_company_add_inspection)
    RelativeLayout mRelaCompanyAddInspection;
    @Bind(R.id.line_action)
    LinearLayout mLineAction;
    private CompanyInfo mCompanyInfo;
    private NaviLatLng mEnd;
    private boolean mIsShowAction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_company_detial);
        ButterKnife.bind(this);
        init();
    }

    @Override
    protected void initSP() {

    }

    public static Intent newIntent(Context context, CompanyInfo companyInfo,boolean isShowAction) {
        Intent intent = new Intent(context, CompanyDetialActivity.class);
        intent.putExtra(Constant.INTENT_KEY.COMPANYINFO, companyInfo);
        intent.putExtra(Constant.INTENT_KEY.IS_SHOW_ACTION, isShowAction);
        return intent;
    }

    @Override
    protected void initIntent() {
        Intent intent = getIntent();
        mCompanyInfo = (CompanyInfo) intent.getSerializableExtra(Constant.INTENT_KEY.COMPANYINFO);
//        Log.e("initIntent ", "initIntent "+companyInfo);
        mIsShowAction = intent.getBooleanExtra(Constant.INTENT_KEY.IS_SHOW_ACTION, false);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void findID() {
    }

    @Override
    protected void initViews() {
        mTextViewCompanyName.setText(mCompanyInfo.getCompanyName());
        mTextViewAddress.setText(mCompanyInfo.getCompanyAddress());
        mTextViewPhone.setText(mCompanyInfo.getCompanyPhone());
        if(mIsShowAction){
            mLineAction.setVisibility(View.VISIBLE);
        }else{
            mLineAction.setVisibility(View.GONE);
        }
    }

    @Override
    protected void setListeners() {

    }

    @OnClick({R.id.imgBack, R.id.image_menu, R.id.rela_company_GPS,R.id.rela_company_inspection_record, R.id.rela_company_add_inspection})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.imgBack:
                finishTo();

                break;
            case R.id.image_menu:
                showPopupMenu(mImageMenu);

                break;
            case R.id.rela_company_GPS:
                ToastUtils.showShortToast(this, "GPS");
                Intent intent = NavigateActivity.newIntent(this, mCompanyInfo);
                startActivityTo(intent);
                break;
            case R.id.rela_company_inspection_record:

                break;
            case R.id.rela_company_add_inspection:

                break;


        }
    }

    private void showPopupMenu(View view) {
        // View当前PopupMenu显示的相对View的位置
        PopupMenu popupMenu = new PopupMenu(this, view);
        // menu布局
        popupMenu.getMenuInflater().inflate(R.menu.menu_company_detial, popupMenu.getMenu());
        // menu的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_update:
                        Intent intent = AddCompanyActivity.newIntent(CompanyDetialActivity.this, mCompanyInfo);
                        startActivityTo(intent);
                        break;
                    case R.id.menu_delete:
                        ToastUtils.showShortToast(CompanyDetialActivity.this, "删除了企业信息");
                        break;
                }
                return false;
            }
        });
        popupMenu.show();
    }

}
